<?php
namespace app\index\controller;
use think\Db;
class Address{
	public function queryAll(){
		$address = Db::query('select * from address');
		return json(["code"=>200,"data"=>$address]);
	}
	public function queryDefaultAddress(){
		$address = Db::query('select * from address where defaultAddress=1');
		return json(["code"=>200,"data"=>$address]);
	}
	public function add(){
		$name = input('post.name');
		$phone = input('post.phone');
		$ssq = input('post.ssq');
		$address = input('post.address');
		$defaultAddress = input('post.defaultAddress');
		$r = Db::execute('insert into address (id,name,phone,ssq,address,defaultAddress) values (null,?,?,?,?,?)',[$name,$phone,$ssq,$address,(int)$defaultAddress]);
	}
	public function queryById(){
		$id=input('get.id');
		$address = Db::query('select * from address where id=?',[$id]);
		return json(["code"=>200,"data"=>$address]);
	}
	public function delete(){
		$id=input('get.id');
		$r= Db::execute('delete from address where id=?',[$id]);
	}
}